// 菜单数据
interface menuArray {
  name: string
  icon?: string
  children: menuItem[]
}
interface menuItem {
  name: string
  url: string
  icon?: string
}
const menuArr: menuArray[] = [
  {
    name: '基础数据管理',
    icon: 'el-icon-notebook-1',
    children: [
      {
        name: '清算日历表',
        url: '/basicData/Calendar'
      }
    ]
  },
  {
    name: '运价维护',
    icon: 'el-icon-set-up',
    children: [
      {
        name: '基础运价',
        url: '/tariff/freightRate'
      },
      {
        name: '包舱',
        url: '/tariff/packageCabin'
      },
      {
        name: '单票',
        url: '/tariff/singleTicket'
      },
      {
        name: '杂费运价',
        url: ''
      }
    ]
  },
  {
    name: '清算报告',
    icon: 'el-icon-tickets',
    children: [
      {
        name: '清算报告(航司)',
        url: ''
      },
      {
        name: '销售汇总表',
        url: ''
      }
    ]
  },
  {
    name: '单据管理',
    icon: 'el-icon-folder-opened',
    children: [
      {
        name: '货单审核',
        url: ''
      },
      {
        name: '正式账单',
        url: ''
      },
      {
        name: '手工账单',
        url: ''
      },
      {
        name: '运单数据',
        url: ''
      },
      {
        name: 'CCA数据',
        url: ''
      },
      {
        name: '舱单数据',
        url: ''
      }
    ]
  },
  {
    name: '付款结果管理',
    icon: 'el-icon-money',
    children: [
      {
        name: '付款结果查询',
        url: ''
      }
    ]
  }
]

// 日期转化
function dateToYear(date: string): string {
  return date.slice(0, 10)
}

// 日期转换封装
import day from 'dayjs'
export const dayFormat = (date: Date, str: string) => {
  return day(date).format(str)
}

// 分页默认值
const pagingConfig = {
  currentPage: 1,
  pageSizes: [5, 10, 20, 30, 40, 50, 100],
  pageSize: 20,
  total: 0
}

export const pageOrigin = {
  page: 1,
  size: 20
}

// 状态
const status = ['启用', '作废', '终止']
export { menuArr, dateToYear, pagingConfig, status }

// 图片转化 base64
export const transformArrayBufferToBase64 = (buffer: any) => {
  let binary = ''
  const bytes = new Uint8Array(buffer)
  for (let len = bytes.byteLength, i = 0; i < len; i++) {
    binary += String.fromCharCode(bytes[i])
  }
  return window.btoa(binary)
}

// 判断时间
export const isToday = () => {
  const date = new Date()
  const hour = date.getHours()
  if (hour < 12) {
    return '早上好,陌生人'
  } else if (hour === 12) {
    return '中午好,陌生人'
  } else {
    return '下午好,陌生人'
  }
}

// toFormData
export const toFormData = function (val: any) {
  const formData = new FormData()
  for (const i in val) {
    isArray(val[i], i)
  }

  function isArray(array: any[] | any, key: string) {
    if (array instanceof Date) {
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      formData.append(key, array)
    }
    if (array == undefined || typeof array == 'function') {
      return false
    }
    if (typeof array != 'object') {
      formData.append(key, array)
    } else if (array instanceof Array) {
      if (array.length == 0) {
        formData.append(`${key}`, '')
      } else {
        for (const i in array) {
          // 判断文件
          if (array[i] instanceof File) {
            formData.append(`${key}`, array[i])
          } else if (typeof array[i] != 'object') {
            formData.append(`${key}`, array[i])
          } else {
            for (const j in array[i]) {
              isArray(array[i][j], `${key}[${i}].${j}`)
            }
          }
        }
      }
    } else {
      const arr = Object.keys(array)
      // 封装的upload组件返回的是文件对象，需要处理
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      if (array[0] && array[0] instanceof File) {
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        for (const t in array) {
          formData.append(`${key}`, array[t])
        }
      } else {
        if (arr.indexOf('uid') == -1) {
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          for (const j in array) {
            isArray(array[j], `${key}.${j}`)
          }
        } else {
          formData.append(`${key}`, array)
        }
      }
    }
  }
  return formData
}

// 状态转换
export const rariffState = ['启用', '作废', '终止']
